package com.ehotting.mqbd.core.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.PropertyFilter;
import com.ehotting.mqbd.api.bean.MQDataAble;

public class MQJsonUtil {

    public String toJSONString(MQDataAble data){

        PropertyFilter propertyFilter = new PropertyFilter() {
            @Override
            public boolean apply(Object object, String name, Object value) {
                MQDataAble data = (MQDataAble)object;
                if(data.isLogRequest()==false && "request".equals(name)){
                    return false;
                }

                if(data.isSendResponse()==false && "response".equals(name)){
                    return false;
                }

                return true;
            }
        };

        return JSON.toJSONString(data, propertyFilter);

    }
}
